const path = require('path')
const newsControllers = require('../services/index');
const { weatherApi, HWeatherApi } = require('../api/index');
module.exports = {
    async getData (ctx) {
        let data = await newsControllers.getList(ctx)
        ctx.body = {
            success: true,
            data,
            message: '操作成功',
            code: 200
        };
    },
    async render (ctx) {
        let data = await newsControllers.getList(ctx)
        let params = {}
        params.location = ctx.query.location || '深圳'
        let weather = await weatherApi.getWeatherNow(params)
        let pageData = {
            data,
            weather: weather.results,
            query: ctx.query || {}
        }
        await ctx.render({
            path: path.resolve(__dirname, '../views/pages/news.vue'),
            components: {
                Layout: path.resolve(__dirname, '../views/layout/index.vue'),
                Header: {
                    path: path.resolve(__dirname, '../views/layout/header.vue'),
                    data () {
                        return {
                            ...pageData
                        }
                    },
                },
                Tabs: {
                    path: path.resolve(__dirname, '../views/layout/tabs.vue'),
                    data () {
                        return {
                            ...pageData
                        }
                    },
                }
            },
            data () {
                return {
                    isShowTop: true,
                    ...pageData
                }
            },
            mounted () {
                window.addEventListener('scroll', handleScroll)
            },
            methods: {
            }
        })
    }
}